package com.lpb.spring.test1;

import com.google.common.collect.Maps;

import java.util.Map;

/**bean工厂
 * 注册、获取bean
 * @author linpengbo
 * @date 2022/4/24
 */
public class BeanFactory {
    private  Map<String,BeanDefinition> beanMap= Maps.newConcurrentMap();

    private BeanFactory(){

    }

    private static class InnerFactory{
        private static  BeanFactory instance=new BeanFactory();
    }

    public static BeanFactory  getInstance(){
     return InnerFactory.instance;
    }

    public  void registerBeanDefinition(String beanName,BeanDefinition definition){
        beanMap.put(beanName,definition);
    }

    public  Object getBean(String beanName){
        return beanMap.get(beanName).getBean();
    }

    public static void main(String[] args) {
        BeanFactory instance = BeanFactory.getInstance();
        BeanFactory instance1 = BeanFactory.getInstance();
        System.out.println(instance==instance1);

    }
}
